package com.tanhua.admin.controller;

import com.bilibili.model.vo.FreezeVo;
import com.bilibili.model.vo.PageResult;
import com.bilibili.model.vo.UnfreezeVo;
import com.bilibili.model.vo.UserInfoVoAge;
import com.tanhua.admin.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author HuangRongFu
 * 2021/11/29 星期一8:22 上午
 */

@RequestMapping("/manage")
@RestController
public class ManageController {

    @Autowired
    private ManageService manageService;


    /**
     * 用户管理 分页查询
     * @param page
     * @param pageSize
     * @Return: ResponseEntity
     */
    @GetMapping("/users")
    public ResponseEntity findPage(@RequestParam(defaultValue = "1") Long page,
                                   @RequestParam(defaultValue = "10",value = "pagesize") Long pageSize){

        PageResult<UserInfoVoAge> pageResult = manageService.findPage(page, pageSize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询用户详细
     * @param userId
     * @Return: ResponseEntity
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity getUserInfo(@PathVariable Long userId){

        UserInfoVoAge vo = manageService.findById(userId);

        return ResponseEntity.ok(vo);
    }

    /**
     * 冻结用户
     * @param freeze
     * @Return: ResponseEntity
     */
    @PostMapping("/users/freeze")
    public  ResponseEntity freezeUser(@RequestBody FreezeVo freeze){

        Map<String, String> resultMap = manageService.freezeUser(freeze);

        return ResponseEntity.ok(resultMap);
    }

    /**
     * 解冻用户
     * @param unfreezeVo
     * @Return: ResponseEntity
     */
    @PostMapping("/users/unfreeze")
    public  ResponseEntity unfreezeUser(@RequestBody UnfreezeVo unfreezeVo){

        Map<String, String> resultMap = manageService.unfreezeUser(unfreezeVo);

        return ResponseEntity.ok(resultMap);
    }
}
